export default {
    data () {
        return {
           ispwd:false,
           loginForm:{
               username:'',
               password:''
           },
           loginFromRules:{
                  username:[
                      { required: true, message: '请输入登录名', trigger: 'blur' },
                      { min: 3, max: 6, message: '长度在 3 到 6 个字符', trigger: 'blur' }
                  ],
                  password:[
                      { required: true, message: '请输入密码', trigger: 'blur' },
                      { min: 3, max: 8, message: '长度在 3 到 8个字符', trigger: 'blur' }
                  ]
           }
        }
    },
    methods:{
        reset(){
            this.$refs.loginFormRef.resetFields();
        },
        login(){
            this.$refs.loginFormRef.validate(async valid=>{
                // console.log(valid)
                if(!valid) return this.$message.error('请填写完整的登陆信息')
          const {data:res}  =  await this.$http.post('login',this.loginForm)
          if(res.meta.status !==200) return this.$message.error('登录失败')
           this.$message.success('登录成功')
           console.log(res)
            sessionStorage.setItem('token',res.data.token)
            this.$router.push('/home')
            })
        }
    }
}